#ifndef PERSISTOR_H
#define PERSISTOR_H

#include "../common/utils/Logger.h"
#include "../common/Constantes.h"
#include "./Scenario.h"
#include "./tinyxml/tinyxml.h"
#include <list>
#include "../common/DTOTipoAsteroide.h"
#include "../common/DTOAsteroide.h"
#include "TipoAsteroide.h"
#include "../SDLtoolkit/Asteroide.h"
#include "../SDLtoolkit/widgets/Ship.h"
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"

#define PERSISTER_SUCCESS 0
#define INVALID_FILE -1
#define INVALID_ROOT_VALUE -2

class Persistor {

public:

	static int getElements(std::string scenarioName,std::list<Asteroide*>&);
	static ShipStatus* getShipByName(std::string shipName);
	static void getDimensions(std::string scenarioName,int* width, int* height);
	static std::string getScenarioFile(std::string scenarioName);
	static std::list< std::pair<std::string,std::string>* >* getShipsModels();

private:

	static int getTiposAsteroide(TiXmlElement* root,std::list<DTOTipoAsteroide*>& tiposAsteroide);

	static int getAsteroides(TiXmlElement* root,std::list<DTOAsteroide*>& asteroides,std::list<DTOTipoAsteroide*>& tiposAsteroide);

	static int getShips(TiXmlElement* root,std::list< std::pair<std::string,DTOShipStatus*>* >* ship);

	static DTOTipoAsteroide* findAsteroideType(std::string tipoString,std::list<DTOTipoAsteroide*>& tiposAsteroide);

	static bool existsAsteroideType(std::string tipoString,std::list<DTOTipoAsteroide*> tiposAsteroide);

	static void resolveOverlaping(const std::list<DTOAsteroide*>& asteroides,DTOShipStatus* dtoShipStatus);

	static bool isOverlapping(DTOAsteroide* asteroide,DTOShipStatus* dtoShipStatus);

	static int getRandValueInRange(bool isWidth);

	static SDL_Surface* loadSurface(std::string path);

	static std::pair<std::string,DTOShipStatus*>* getShip(TiXmlElement *shipElement);

};
#endif
